// JavaScript Document
function stopAllFlashPlayers(){
//dummy function to avoid javascipt error on admin page
}
//#################################################################

function moveDiv(ID){

//Determine Window Sizes
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }

  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    //myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    //myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    //myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }


var newY = ((myHeight/3) + scrOfY) + 'px';
dojo.byId(ID).style.visibility = 'visible';
dojo.byId(ID).style.top = newY;
}

//#################################################################


function editFromPreview(regionalOnly){
if(regionalOnly!=1){
	var url = 'index.php?op=editLocal&currentID=1&ID='+storyID;
}else{
	var url = 'index.php?op=editRegional&currentID=3&ID='+storyID;
}
	window.location = url;
}

//#################################################################


function deleteFromPreview(regionalOnly){
if(regionalOnly!=1){
	var url = 'index.php?op=deleteStory&currentID=1&ID='+storyID;
}else{
	var url = 'index.php?op=deleteStory&regionalOnly=true&currentID=3&ID='+storyID;

}
	window.location = url;
}

//#################################################################


function displayMediaPlayer(soundFile,regionalOnly){
	if(regionalOnly != 'true'){
		var player = "<!--BEGIN MP3 PLAYER--><object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='300' height='75' id='mp3Player' align='middle'><param name='allowScriptAccess' value='sameDomain' /><param name='movie' value='../media/mp3Player.swf' /><param name='quality' value='high' /><param name='bgcolor' value='#ffffff' /><PARAM NAME=FlashVars VALUE='file=../media/audio/" + soundFile + "&autoPlayStart=true'><embed src='../media/mp3Player.swf' FlashVars='file=../media/audio/" + soundFile + "&autoPlayStart=true' quality='high' bgcolor='#ffffff' width='300' height='75' name='mp3Player' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></object><!--END MP3 PLAYER-->"
	}else{
		var player = "<!--BEGIN MP3 PLAYER--><object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='300' height='75' id='mp3Player' align='middle'><param name='allowScriptAccess' value='sameDomain' /><param name='movie' value='../media/mp3Player.swf' /><param name='quality' value='high' /><param name='bgcolor' value='#ffffff' /><PARAM NAME=FlashVars VALUE='file=" + soundFile + "&autoPlayStart=true'><embed src='../media/mp3Player.swf' FlashVars='file=" + soundFile + "&autoPlayStart=true' quality='high' bgcolor='#ffffff' width='300' height='75' name='mp3Player' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></object><!--END MP3 PLAYER-->"
	}
	dojo.byId('soundClip').innerHTML = player;
	
}

//#################################################################

function addBody(){
	dojo.byId('moreLink').style.visibility = 'hidden';
	dojo.byId('spacer').style.display = 'none'; 
	dojo.byId('bodyHolder').style.display = 'block'; 
}

//#################################################################

function hidePreview(){
dojo.byId('preview').style.visibility = 'hidden';
dojo.byId('soundClip').innerHTML = "";
}

//#################################################################


 function displaySpacer(isImage){
 	if(isImage == 'true'){
		dojo.byId('spacer').style.display = 'inline';
	}else{
		dojo.byId('spacer').style.display = 'none';
	}
 }
 
//#################################################################


//DOJO SCRIPT
function showPreview(ID,regionalOnly){	

			dojo.xhrGet({
		        url: "formaction.php?action=previewStory&ID=" + ID + "&regionalOnly=" + regionalOnly,
		        handleAs: "text",
		        timeout: 5000, //Time in milliseconds
		        handle: function(response, ioArgs){
		                //This function handles the response.
		                //Inside this function, the "this" variable
		                //will be the object used as the argument to the dojo.xhrGet() call.
		                if(response instanceof Error){
		                        if(response.dojoType == "cancel"){
		                                //The request was canceled by some other JavaScript code.
		                                console.debug("Request canceled.");
		                        }else if(response.dojoType == "timeout"){
		                                //The request took over 5 seconds to complete.
		                                console.debug("Request timed out.");
		                        }else{
		                                //Some other error happened.
		                                console.error(response);
		                        }
		                }else{//successful query
		                
			                	//return data to page		                	
			                	storyID = ID;
								moveDiv('preview'); 
								dojo.byId('previewDiv').innerHTML = response;
								if(regionalOnly!='true'){
									dojo.byId('buttonsPreview').innerHTML = "<input type='button' class='formButton' name='Edit'  id='edit' value='Edit' onclick='editFromPreview()' /> &nbsp; &nbsp; <input type='button' class='formButton' name='delete'  id='delete' value='Delete' onclick='deleteFromPreview()' /> &nbsp; &nbsp; <input type='button' class='formButton' name='hide'  id='hide' value='Hide' onClick='hidePreview()' />";
								}else{
									dojo.byId('buttonsPreview').innerHTML = "<input type='button' class='formButton' name='Edit'  id='edit' value='Edit' onclick='editFromPreview(1)' /> &nbsp; &nbsp; <input type='button' class='formButton' name='delete'  id='delete' value='Delete' onclick='deleteFromPreview(1)' /> &nbsp; &nbsp; <input type='button' class='formButton' name='hide'  id='hide' value='Hide' onClick='hidePreview()' />";
								}
	                	
		                }
		                
						
		        }
		});	
	
	
	
	
	
}//end function





